package com.ruoyi.standingbook.greenery.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.greenery.domain.bo.GreeneryBo;
import com.ruoyi.standingbook.greenery.domain.vo.GreeneryPicVo;
import com.ruoyi.standingbook.greenery.domain.vo.GreeneryVo;
import com.ruoyi.standingbook.greenery.service.IGreeneryService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 道路绿化管养任务完成进度
 *
 * @author cc
 * @date 2023-08-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/greenery")
public class GreeneryController extends BaseController {

    private final IGreeneryService iGreeneryService;

    /**
     * 查询道路绿化管养任务完成进度列表
     */
    @SaCheckPermission("standingbook:greenery:list")
    @GetMapping("/list")
    public TableDataInfo<GreeneryVo> list(GreeneryBo bo, PageQuery pageQuery) {
        return iGreeneryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出道路绿化管养任务完成进度列表
     */
    @SaCheckPermission("standingbook:greenery:export")
    @Log(title = "道路绿化管养任务完成进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GreeneryBo bo, HttpServletResponse response) {
        List<GreeneryVo> list = iGreeneryService.queryList(bo);
        ExcelUtil.exportExcel(list, "道路绿化管养任务完成进度", GreeneryVo.class, response);
    }

    /**
     * 获取道路绿化管养任务完成进度详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("standingbook:greenery:query")
    @GetMapping("/{id}")
    public R<GreeneryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iGreeneryService.queryById(id));
    }

    /**
     * 新增道路绿化管养任务完成进度
     */
    @SaCheckPermission("standingbook:greenery:add")
    @Log(title = "道路绿化管养任务完成进度", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GreeneryBo bo) {
        return toAjax(iGreeneryService.insertByBo(bo));
    }

    /**
     * 修改道路绿化管养任务完成进度
     */
    @SaCheckPermission("standingbook:greenery:edit")
    @Log(title = "道路绿化管养任务完成进度", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GreeneryBo bo) {
        return toAjax(iGreeneryService.updateByBo(bo));
    }

    /**
     * 删除道路绿化管养任务完成进度
     *
     * @param ids 主键串
     */
    @SaCheckPermission("standingbook:greenery:remove")
    @Log(title = "道路绿化管养任务完成进度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iGreeneryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 按指定日期查询智慧大屏道路绿化台账
     * @param date 指定日期
     * @return
     */
    @SaIgnore()
    @GetMapping("/greeneryByDate")
    public R<List<GreeneryVo>> greeneryByDate(String date,String community) {
        return R.ok(iGreeneryService.queryListByDate(date, community));
    }


    @SaIgnore()
    @GetMapping("/greeneryPic")
    public R<List<GreeneryPicVo>> greeneryPic(String date)  {
        return R.ok(iGreeneryService.getPicByDate(date));
    }
}
